﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using WebManager;

namespace BaoJian.WebManager.eshop
{
    public partial class eproductlist : System.Web.UI.Page
    {
        private string ColumnID = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            ColumnID = HttpContext.Current.Request.QueryString["oid"];
            if(!Page.IsPostBack)
            { 
                BindData();
            }
        }

        protected void Doc_Click(object sender, EventArgs e)
        {
            string url = URLUtility.UrlBase + "/WebManager/eshop/eproductnew.aspx";
            Page.Response.Redirect(url);
        }
        void BindData()
        {
            using (DataSet ds = Tools.Common.GetPage("EProduct", "*", "SID", AspNetPager.PageSize, AspNetPager.CurrentPageIndex, false, true, "", "PID"))
            {
                GridView1.DataSource = ds.Tables[0];
                GridView1.DataBind();
                int totalNum = Convert.ToInt32(Tools.Common.GetPage("EProduct", "*", "SID", AspNetPager.PageSize, AspNetPager.CurrentPageIndex, true, true, "", "PID").Tables[0].Rows[0][0]);
                AspNetPager.RecordCount = totalNum;
            }
        }

        protected void Edit_Click(object sender, EventArgs e)
        {
            string sel = HttpContext.Current.Request.Form["selectCB"];
            if (sel == null)
            {
                return;
            }
            string[] sels = sel.Split(',');
            if (sels.Length > 1)
            {
                LYQ.MessageBox.Show(Page, "每次只能编辑一个产品");
                return;
            }

            string url = URLUtility.UrlBase + "/WebManager/eshop/eproductedit.aspx?ColumnID=" + ColumnID + "&OID=" + sels[0];
            Page.Response.Redirect(url);
        }
      
        protected void Delete_Click(object sender, EventArgs e)
        {
            string sel = HttpContext.Current.Request.Form["selectCB"];
            if (sel == null)
            {
                return;
            }
            string[] sels = sel.Split(',');

            LYQ.BLL.EProduct bll = new LYQ.BLL.EProduct();
            for (int i = 0; i < sels.Length; i++)
            {
                bll.Delete(new Guid(sels[i]));            
            }
            BindData();
        }

        protected void AspNetPager_PageChanged(object sender, EventArgs e)
        {
            BindData();
        }

        
    }
}
